home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-11-09 | 7.2 KB | 241 lines | [TEXT/MPS ] |
- PROGRAM EgretWakeUp;
- {
-
- 11/02/93 DTS
-
- This is a test program to tell a Mac with an Egret (or Egret derivative)
- chip when to power up. It does so by calling the _Egret trap.
-
- If the Power Manager exists, use the SetWUTime call as per Inside
- Macintosh, Power Manager chapter (Vol VI).
-
- This program only works on a Egret-based Macs that ALSO can do soft
- power. For example while the IIsi and LC CPUs both have Egrets, LCs
- can't do soft power on).
-
- I first tried just checking for the Egret trap before making the call,
- but for some reason _Egret exists on Macs that don't have Egrets
- (z.B. QUadra 700,800, Centris 650, Duos).
-
- Calling _Egret on these Macs is FATAL.
-
- Then I found there is a low memory global that has essentially an Egret
- family version number. So this program checks that global. DTS
- will entertain *** no **** questions about this global. Anyone using
- it for any reason other than checking for an Egret does so at EXTREME
- risk of breaking. And in fact even this could break, if the flags
- change for some reason. The flags aren't documented to developers so
- this is fair game. Use this snippet at your own risk!
-
- If the CPU isn't capable of soft power then the call to Egret isn't made.
-
-
- INSTRUCTIONS:
- Set the kMinutesToDelay constant in the CONST section to some number of
- minutes (I set it to 1). Build and then run this program. If the program
- says it can wake up, immediately shut down the Macintosh, and it will power
- up "kMinutesToDelay" minutes after the program is run (not shut down).
-
- If the Mac can't wake up due to lack of Egret or soft power capability,
- it will say so and not call the Egret trap.
-
- useful commands:
- pasmat EgretWakeUp.p -r -u > EgretWakeUp.pasmat
- print "Internal:MPW:EgretWakeUp.p" -b2 -h -md -font Courier -size 7
- print "Internal:MPW:EgretWakeUp.a" -b2 -h -md -font Courier -size 7
- print "Internal:MPW:myEgretEqu.a" -b2 -h -md -font Courier -size 7
- print "Internal:MPW:EgretWakeUp.make" -b2 -h -md -font Courier -size 7
- }
-
-
- USES Memtypes, QuickDraw, OsIntf, ToolIntf, PackIntf, PasLibIntf, GestaltEqu;
-
- CONST
- kProgramVersion = '1.2';
- kMinutesToDelay = 1;
-
- VAR
- gErr: OSErr;
- gPresentTime,
- gWakeUpTime: LONGINT;
-
-
- {-----------------------------------------------------
- HasEgretHW - check for presence of egret/caboose/cuda
- clock chips
- -----------------------------------------------------}
-
- FUNCTION HasEgretHW: BOOLEAN;
-
- CONST
- kMyUnivROMFlags = $00000DD4; { USE AT OWN RISK. UNSUPPORTED BY DTS }
- kEgretClockMask = $00000070; { bits 4,5,6 determine what kind of clock machine has. }
- { if 010 then machine has an Egret style clock chip. }
- kEgretStyle = $00000020; { Egret style machines will equal this after ANDing }
- { (UnivRomFlags & kEgretClockMask) }
- VAR
- gotIt : BOOLEAN;
- ROMFlags : LONGINT;
- ROMFlagPtr : LongIntPtr;
-
- BEGIN
- gotIt := FALSE;
-
- { Is Egret hardware available? }
- ROMFlagPtr := Pointer(kMyUnivROMFlags);
- ROMFlags := ROMFlagPtr^;
-
- gotIt := (BAND(ROMFlags,kEgretClockMask) = kEgretStyle);
-
- If gotIt THEN
- Writeln('Checking for presence of Egret hardware. Result: has Egret hardware.')
- ELSE
- Writeln('Checking for presence of Egret hardware. Result: no Egret hardware.');
- PLFlush(Output);
-
- HasEgretHW := gotIt;
- END;
-
- {-----------------------------------------------------
- HasEgretTrap - check for presence of egret trap.
- -----------------------------------------------------}
-
- FUNCTION HasEgretTrap: BOOLEAN;
-
- CONST
- kEgretTrapNum = $92; { Trap Number of EgretTrapNum }
- kUnImplTrapNum = $9F; { Trap Number of Unimplemented Trap }
-
- BEGIN
- HasEgretTrap := FALSE;
-
- { Is Egret trap available? }
- HasEgretTrap := NGetTrapAddress(kEgretTrapNum, OSTrap) <>
- NGetTrapAddress(kUnImplTrapNum,ToolTrap);
- END;
-
-
- {-----------------------------------------------------
- HasSoftPower - check for soft power off capability
- -----------------------------------------------------}
-
- FUNCTION HasSoftPower: BOOLEAN;
-
- CONST
- kGestaltTrapNum = $AD; { Trap Number of Gestalt }
- kUnImplTrapNum = $9F; { Trap Number of Unimplemented Trap }
-
- VAR
- GestaltIsImplemented: BOOLEAN; { True if Gestalt is implemented }
- gestaltErr: OSErr; { Error returned from Gestalt }
- theHardwareAttr: LONGINT; { attributes holder }
- temp : BOOLEAN;
-
- BEGIN
- temp := FALSE;
-
- { Is Gestalt available? }
- GestaltIsImplemented := NGetTrapAddress(kGestaltTrapNum, OSTrap) <>
- NGetTrapAddress(kUnImplTrapNum, ToolTrap);
-
- IF GestaltIsImplemented THEN BEGIN
- gestaltErr := Gestalt(gestaltHardwareAttr, theHardwareAttr);
- IF gestaltErr = noErr THEN BEGIN
- { use MPW's BTst function }
- IF ( BTst(theHardwareAttr,gestaltHasSoftPowerOff) ) THEN
- temp := TRUE;
- END;
- END;
-
- If temp THEN
- Writeln('Checking for soft power capability. Result: has soft power capability.')
- ELSE
- Writeln('Checking for soft power capability. Result: no soft power capability.');
- PLFlush(Output);
-
- HasSoftPower := temp;
- END;
-
- {-----------------------------------------------------
- SetEgretWakeUpTime - assembly language stub to call
- the Egret trap to set a wakeup time
- -----------------------------------------------------}
-
- PROCEDURE SetEgretWakeUpTime(WakeUpWhen: LONGINT);
- EXTERNAL;
-
-
- {-----------------------------------------------------
- ShowTime - show a prompt string and convert a
- DateTimeRec into hour, minute, seconds
- -----------------------------------------------------}
-
- PROCEDURE ShowTime(thePromptStr: str255; theSeconds: LONGINT);
-
- VAR
- myDateTimeRec: DateTimeRec;
-
- BEGIN
- Secs2Date(theSeconds, myDateTimeRec);
- write(thePromptStr);
- WITH myDateTimeRec DO BEGIN
- write(hour: 2, ':');
- write(minute: 2, ':');
- writeln(second: 2);
- END;
- PLFlush(Output);
- END; {procedure}
-
-
- {-----------------------------------------------------
- QuitProgram
- -----------------------------------------------------}
-
- PROCEDURE QuitProgram;
-
- BEGIN
- writeln;
- writeln('goodbye');
- PLFlush(Output);
- END; {procedure}
-
-
-
- {=====================================================
- Main program
- =====================================================}
-
- BEGIN
- writeln('Program Version number: ', kProgramVersion);
- writeln;
- PLFlush(Output); {SIOW apps need PLFlush after writes to show I/O right away}
-
- IF HasEgretHW THEN BEGIN {has egret hardware}
- {let's see if it has soft power capability as well - we need both}
- IF HasSoftPower THEN BEGIN {has SoftPower}
- gErr := ReadDateTime(gPresentTime); {time in ticks}
- IF gErr = noErr THEN BEGIN
- writeln;
- ShowTime('The present time is:', gPresentTime);
- gPresentTime := gPresentTime + (kMinutesToDelay * 60);
- ShowTime('I will wake up at:', gPresentTime);
-
- {debugStr('ready to call SetEgretWakeUpTime');}
-
- IF HasEgretTrap THEN
- SetEgretWakeUpTime(gPresentTime); {this assembly stub calls Egret trap}
- END {has SoftPower}
- END
- ELSE BEGIN {No soft power}
- writeln('No soft power - unable to set a wakeup time.');
- PLFlush(Output);
- END {No soft power}
- END {has egret hardware}
- ELSE BEGIN {no egret}
- writeln('No egret - unable to set a wakeup time.');
- PLFlush(Output);
- END; {no egret}
-
- QuitProgram;
- END.
-